home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995 August: Tool Chest / Dev.CD Aug 95 TC / Dev.CD Aug 95 TC.toast / Sample Code / AOCE Sample Code / SampleTemplate / Sample Template / Source / AlbumCode2Page2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-23  |  3.9 KB  |  175 lines  |  [TEXT/MPS ]

  1. #ifndef __ALBUM__
  2. #include "Album.h"
  3. #endif
  4.  
  5. #ifndef __OCETEMPLATES__
  6. #include <OCETemplates.h>
  7. #endif
  8.  
  9. #ifndef __TRACK__
  10. #include "Track.h"
  11. #endif
  12.  
  13. static OSErr DoIdle(DETCallBlockPtr callBlockPtr);
  14.  
  15. pascal OSErr AlbumCode(DETCallBlockPtr callBlockPtr)
  16.     {
  17.     OSErr err = 1;
  18.     
  19.     if ((callBlockPtr->protoCall.reqFunction < kDETcmdTargetedCall) || (callBlockPtr->protoCall.target.selector == kDETSelf))
  20.         {
  21.         switch (callBlockPtr->protoCall.reqFunction)
  22.             {
  23.             case kDETcmdInit:
  24.                 callBlockPtr->init.newCallFors = kDETCallForIdle + kDETCallForViewChanges;
  25.                 break;
  26.             
  27.             case kDETcmdIdle:
  28.             case kDETcmdViewListChanged:
  29.                 err = DoIdle(callBlockPtr);
  30.                 break;
  31.  
  32.             }
  33.         }
  34.     
  35.     return err;
  36.     }
  37.  
  38. static OSErr GetPropertyNumber(DETCallBlockPtr callBlockPtr, DETTargetSelector selector, long itemNumber, short property, long *value)
  39.     {
  40.     OSErr err;
  41.     DETCallBackBlock cbb;
  42.     
  43.     cbb.getPropertyNumber.reqFunction = kDETcmdGetPropertyNumber;
  44.     cbb.getPropertyNumber.property = property;
  45.     
  46.     cbb.getPropertyNumber.target.selector = selector;
  47.     cbb.getPropertyNumber.target.aspectName = nil;
  48.     cbb.getPropertyNumber.target.itemNumber = itemNumber;
  49.  
  50.     err = CallBackDET(callBlockPtr, &cbb);
  51.     
  52.     *value = cbb.getPropertyNumber.propertyValue;
  53.     
  54.     return err;
  55.     }
  56.  
  57. static OSErr GetNumSublistItems(DETCallBlockPtr callBlockPtr, long *num)
  58.     {
  59.     OSErr err;
  60.     DETCallBackBlock cbb;
  61.     
  62.     cbb.sublistCount.reqFunction = kDETcmdSublistCount;
  63.     cbb.sublistCount.target.selector = kDETSelf;
  64.  
  65.     err = CallBackDET(callBlockPtr, &cbb);
  66.     
  67.     *num = cbb.sublistCount.count;
  68.         
  69.     return err;
  70.     }
  71.  
  72. static OSErr SetPropertyNumber(DETCallBlockPtr callBlockPtr,
  73.                                short property,
  74.                                long newValue)
  75.     {
  76.     OSErr err;
  77.     DETCallBackBlock cbb;
  78.     
  79.     cbb.setPropertyNumber.reqFunction = kDETcmdSetPropertyNumber;
  80.     cbb.setPropertyNumber.property = property;
  81.     cbb.setPropertyNumber.target.selector = kDETSelf;
  82.     cbb.setPropertyNumber.newValue = newValue;
  83.  
  84.     err = CallBackDET(callBlockPtr, &cbb);
  85.     
  86.     return err;
  87.     }
  88.  
  89. static OSErr DoIdle(DETCallBlockPtr callBlockPtr)
  90.     {
  91.     OSErr err;
  92.     long oldNumber, actualNumber;
  93.     
  94.     err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prNumTracks, &oldNumber);
  95.     
  96.     if (err == noErr)
  97.         {
  98.         err = GetNumSublistItems(callBlockPtr, &actualNumber);
  99.         }
  100.  
  101.     if ((err == noErr) && (oldNumber != actualNumber))
  102.         {
  103.         err = SetPropertyNumber(callBlockPtr, prNumTracks, actualNumber);
  104.         }
  105.  
  106.     if (err == noErr)
  107.         {
  108.         long index;
  109.         long oldSeconds, actualSeconds = 0;
  110.         long seconds;
  111.         long minutes;
  112.         long hours;
  113.         
  114.         // First add up the real playing time by asking each track for its playing time.
  115.         for (index = 1; (err == noErr) && (index <= actualNumber); ++index)
  116.             {
  117.             err = GetPropertyNumber(callBlockPtr, kDETSublistItem, index, prTrackSeconds, &seconds);
  118.             
  119.             if (err == noErr)
  120.                 {
  121.                 err = GetPropertyNumber(callBlockPtr, kDETSublistItem, index, prTrackMinutes, &minutes);
  122.                 }
  123.             
  124.             if (err == noErr)
  125.                 {
  126.                 actualSeconds += (minutes * 60 + seconds);
  127.                 }
  128.             }
  129.         
  130.         // Get the old total playing time.
  131.         if (err == noErr)
  132.             {
  133.             err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prPlayingTimeHours, &hours);
  134.             }
  135.  
  136.         if (err == noErr)
  137.             {
  138.             err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prPlayingTimeMinutes, &minutes);
  139.             }
  140.             
  141.         if (err == noErr)
  142.             {
  143.             err = GetPropertyNumber(callBlockPtr, kDETSelf, 0, prPlayingTimeSeconds, &seconds);
  144.             }
  145.         
  146.         // Now compare the two playing times and, if they're different, take the new one.
  147.         if (err == noErr)
  148.             {
  149.             oldSeconds = 3600 * hours + 60 * minutes + seconds;
  150.             
  151.             if (oldSeconds != actualSeconds)
  152.                 {
  153.                 hours = actualSeconds / 3600;
  154.                 err = SetPropertyNumber(callBlockPtr, prPlayingTimeHours, hours);
  155.                 
  156.                 if (err == noErr)
  157.                     {
  158.                     actualSeconds -= (hours * 3600);
  159.                     minutes = actualSeconds / 60;
  160.                     err = SetPropertyNumber(callBlockPtr, prPlayingTimeMinutes, minutes);
  161.                     }
  162.             
  163.                 if (err == noErr)
  164.                     {
  165.                     actualSeconds -= (minutes * 60);
  166.                     err = SetPropertyNumber(callBlockPtr, prPlayingTimeSeconds, actualSeconds);
  167.                     }
  168.                 }
  169.             }
  170.         }
  171.  
  172.     return err;
  173.     }
  174.  
  175.